#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int file_len(FILE *fp)
{
	int len = 0;

	if(fp == NULL){
		return 0;
	}
	int pos = ftell(fp);
	
	fseek(fp, 0, SEEK_END);
	len = ftell(fp);

	fseek(fp, pos, SEEK_SET);

	return len;
}

int file_content(FILE *fp, char **buf)
{
	int len = 0;
	char *p ;
	if(fp == NULL || buf == NULL){
		return 0;
	}
	
	len = file_len(fp);
	p = *buf = malloc(len);	

	while(!feof(fp)){
		*(*buf)++ = getc(fp);
	}
	*buf = p;
	return len;
}

void get_type(char *file_name, char *type)
{
	int len = strlen(file_name);
	int i;

	for(i=len-1; file_name[i]!='.'; i--);
	strcpy(type, file_name + i + 1);
}

